package com.sanley.piss.web.service;


import com.sanley.piss.mapper.OrganizationMapper;
import com.sanley.piss.model.ServiceImpl;
import com.sanley.piss.model.StringUtil;
import com.sanley.piss.model.exceptionUtil.exception.ServiceException;
import com.sanley.piss.model.po.Organization;
import com.sanley.piss.web.service.mapper.IOrganizationService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;


/**
 * @author 张凯大天才
 */
@Service
@Primary
@Transactional(rollbackFor = ServiceException.class)
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements IOrganizationService {

    @Override
    public void insert(Organization organization) {
        organization.setState(0);
        organization.setGmtCreate(LocalDateTime.now());
        baseMapper.insert(organization);
    }

    @Override
    /**
     * 修改信息
     */
    public void updateById(Organization organization) {
        baseMapper.updateById(organization);

    }

    @Override
    public void removeByIds(Integer[] ids) {
        baseMapper.removeByIds(ids);
    }

    @Override
    public Organization selectById(Integer id) {
        Organization selectOne = baseMapper.selectById(id);
        if (StringUtil.isNull(selectOne)) {
            throw new ServiceException("信息不存在");
        }
        return selectOne;
    }
}